package com.kyxx.topics;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kyxx.topics.activity.SwipeBaseActivity;
import com.kyxx.topics.utils.ToastUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.pgyersdk.activity.FeedbackActivity;
import com.pgyersdk.feedback.PgyFeedbackShakeManager;

/**
 * Created by Administrator on 2016/9/8.
 */
public abstract class BaseActivity2 extends AppCompatActivity {
    protected Context context;
    protected ImageLoader imageLoader;
    protected DisplayImageOptions options = null;
    protected ImageView top_bar_iv_left;
    protected ImageView top_bar_iv_right;
    protected TextView top_bar_tv_left;
    protected TextView top_bar_tv_right;
    protected TextView top_bar_tv_title;
    protected RelativeLayout top_bar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        context = getApplicationContext();
        imageLoader = ImageLoader.getInstance();
        options = options = new DisplayImageOptions.Builder().cacheInMemory(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .showImageOnFail(R.mipmap.image_default)
                .showImageOnLoading(R.mipmap.image_default)
                .showImageForEmptyUri(R.mipmap.image_default)
                .build();
        initView();
    }

    private void initView() {
        loadViewLayout();
        findViewById();
        setListener();
        processLogic();
    }

    protected void loadTopBar(String title) {
        top_bar_iv_left = (ImageView) findViewById(R.id.top_bar_iv_left);
        top_bar_iv_right = (ImageView) findViewById(R.id.top_bar_iv_right);
        top_bar_tv_left = (TextView) findViewById(R.id.top_bar_tv_left);
        top_bar_tv_right = (TextView) findViewById(R.id.top_bar_tv_right);
        top_bar_tv_title = (TextView) findViewById(R.id.top_bar_title);
        top_bar = (RelativeLayout) findViewById(R.id.top_bar);
        top_bar_tv_title.setText(title);
    }

    /**
     * @author txiuqi
     * @描述 加载布局文件
     */
    protected abstract void loadViewLayout();

    /**
     * @描述 根据ID查找控件
     */
    protected abstract void findViewById();

    /**
     * @描述 设置监听
     */
    protected abstract void setListener();

    /**
     * @描述 处理业务
     */
    protected abstract void processLogic();

    public void showToast(String msg) {
        ToastUtils.show(this, msg);
    }

    public void startActivity(Class target) {
        Intent intent = new Intent(this, target);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
//        PgyFeedbackShakeManager.unregister();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        // 自定义摇一摇的灵敏度，默认为950，数值越小灵敏度越高。
//        PgyFeedbackShakeManager.setShakingThreshold(800);
//
//        // 以对话框的形式弹出
////        PgyFeedbackShakeManager.register(MainActivity.this);
//
//        // 以Activity的形式打开，这种情况下必须在AndroidManifest.xml配置FeedbackActivity
//        // 打开沉浸式,默认为false
//        FeedbackActivity.setBarImmersive(true);
//        PgyFeedbackShakeManager.register(this, false);
    }

}
